package mx.com.matersys.vacs.web;

import mx.com.matersys.vacs.domain.GenericResponse;
import mx.com.matersys.vacs.domain.TipoEspecialista;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import flexjson.JSONSerializer;

@RooWebScaffold(path = "tipoespecialistas", formBackingObject = TipoEspecialista.class)
@RequestMapping("/tipoespecialistas")
@Controller
public class TipoEspecialistaController {
	
	@RequestMapping(value = "/addTipoEspecialista", method = RequestMethod.POST)
	public ResponseEntity<String> addPlanServicio(TipoEspecialista tipoEspecialista) {
		
		HttpHeaders headers;
		String json;
		GenericResponse gRes;
		ResponseEntity<String> response;
		
		headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.add("Content-Type", "application/text; charset=utf-8");
		
		System.out.println(tipoEspecialista);
		
		tipoEspecialista.persist();
		
		gRes = new GenericResponse(Boolean.TRUE, tipoEspecialista);
		json = new JSONSerializer().exclude("*.class").serialize(gRes);
		
		response = new ResponseEntity<String>(json, headers, HttpStatus.OK);
		
		return response; 
	}
	
	@RequestMapping(value = "/readTipoEspecialista", method = RequestMethod.GET)
	public ResponseEntity<String> readTipoEspecialista(
			@RequestParam(value = "id", required = false) Integer idtipoespecialista) {
		
		HttpHeaders headers;
		String json;
		GenericResponse gRes;
		ResponseEntity<String> response;
		TipoEspecialista tipoEspecialista;
		
		headers = new HttpHeaders();
		headers.set("Content-Type", "application/json");
		headers.add("Content-Type", "application/text; charset=utf-8");
		
		tipoEspecialista = TipoEspecialista.findTipoEspecialista(idtipoespecialista);
		
		gRes = new GenericResponse(Boolean.TRUE, tipoEspecialista);
		json = new JSONSerializer().exclude("*.class").serialize(gRes);
		
		response = new ResponseEntity<String>(json, headers, HttpStatus.OK);
		
		return response; 
	}
}
